import { RouterMount, createRouter } from '../../js_sdk/hhyang-uni-simple-router/uni-simple-router.js'

import { ACCESS_TOKEN } from '@/common/util/constants.js'

// import modules from './module/'

const router = createRouter({
	platform: process.env.VUE_APP_PLATFORM,  
	// routes: [...modules] ,
	routes: [...ROUTES]
});

const whiteList = ['/pages/login/login', '/pages/index/index']		// 防止重复调用前置守卫

//全局路由前置守卫
router.beforeEach((to, from, next) => {
	
	let token=uni.getStorageSync(ACCESS_TOKEN);
	
	if(token){
		 next()
	}else{
		if (whiteList.indexOf(to.path) !== -1) {
		  next()
		}else{
			next({path: "/pages/index/index"});
		}
	} 
	
	
});
// 全局路由后置守卫
router.afterEach((to, from) => {
    console.log('跳转结束')
})

export {
	router,
	RouterMount
}